const { ccclass, property } = cc._decorator;

import n from "./AbTestMgr"
import l from "./PeripheralSystemDataMgr"
import s from "./EventMgr"
import c from "./GameEventType"
import u from "./frameworkManager"
import p from "./EngineUtil"
import d from "./MatchGameData"
import h from "./PeripheralSystemMgr"
import f from "./RollingNotice"

var _ = ["<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>北京, </color><color=#EAEAEA>获得红包</color><color=#FF6630>10000元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>北京, </color><color=#EAEAEA>提现比例提升</color><color=#FF6630>120%!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>北京, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>提现</color><color=#FF6630>money元</color><color=#EAEAEA>旅游补贴!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>打卡</color><color=#FF6630>30天, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>"]
@ccclass
export default class RollingNoticeCtrl extends cc.Component {
    public runCount = 0;
    public sroll_msg_list = null;
    public fTypeCount = 0;
    public fNode = null;
    public sNode = null;
    public topY = null;

    public onLoad() {
        this.onUILoad();
        this.addEvent();
        this.addButtonListen();
        this.dealReplacePlaceName();
        super.onLoad();
    };
    public start() { };
    public oppoReview() {
        d.isOppoChannel() && (_ = ["<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>获得红包</color><color=#FF6630>10000元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>提现比例提升</color><color=#FF6630>120%!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>提现</color><color=#FF6630>money元</color><color=#EAEAEA>旅游补贴!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>打卡</color><color=#FF6630>30天, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>"]);
    };
    public dealReplacePlaceName() {
        var e = n.isDmthFlag(), t = l.isHitOppoReviewBan();
        n.getDmth2Ab1() ? _ = ["<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>获得红包</color><color=#FF6630>10000元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>提现比例提升</color><color=#FF6630>120%!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>提现</color><color=#FF6630>money元</color><color=#EAEAEA>旅游补贴!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>打卡</color><color=#FF6630>30天, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>"] : n.getDmth2Ab2() ? _ = ["<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>长城, </color><color=#EAEAEA>获得红包</color><color=#FF6630>10000元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>长城, </color><color=#EAEAEA>提现比例提升</color><color=#FF6630>120%!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>长城, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>提现</color><color=#FF6630>money元</color><color=#EAEAEA>旅游补贴!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>打卡</color><color=#FF6630>30天, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>"] : e ? _ = t ? ["<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>获得红包</color><color=#FF6630>10000元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>提现比例提升</color><color=#FF6630>120%!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>提现</color><color=#FF6630>money元</color><color=#EAEAEA>旅游补贴!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>打卡</color><color=#FF6630>30天, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>"] : ["<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>京城, </color><color=#EAEAEA>获得红包</color><color=#FF6630>10000元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>京城, </color><color=#EAEAEA>提现比例提升</color><color=#FF6630>120%!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>京城, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>提现</color><color=#FF6630>money元</color><color=#EAEAEA>旅游补贴!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>打卡</color><color=#FF6630>30天, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>"] : d.isOppoChannel() && (_ = ["<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>获得红包</color><color=#FF6630>10000元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>提现比例提升</color><color=#FF6630>120%!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>到达</color><color=#FFA76D>终点, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>提现</color><color=#FF6630>money元</color><color=#EAEAEA>旅游补贴!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>打卡</color><color=#FF6630>30天, </color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>", "<b><color=#FFA76D>name</color><color=#EAEAEA>红包提现</color><color=#FF6630>money元!</color></b>"]);
    };
    public ui;
    public onUILoad() {
        this.ui = this.node.addComponent(f);
    };
    public addEvent() {
        s.listen(c.UPDATE_SCOLL_MSG, this.updateScollMsg, this);
    };
    public addButtonListen() { };
    public initData(e) {
        if (e) {
            this.sroll_msg_list = e;
            u.log("sroll_msg_list", this.sroll_msg_list);
            this.runNoticeAction();
        }
    };
    public dealShowDes(e, t) {
        void 0 === e && (e = false);
        if (e) {
            this.fTypeCount = 1;
            this.setShowDes(this.sroll_msg_list[0], this.ui.firstNode);
            this.setShowDes(this.sroll_msg_list[1], this.ui.secondNode);
        } else {
            var a = this.sroll_msg_list[this.runCount - 1];
            this.setShowDes(a, t);
        }
    };
    public setShowDes(e, t) {
        var a = t.getChildByName("headMask").getChildByName("headframe"), o = t.getChildByName("messageRichText"), i = e.extract, r = p.subUserName(e.name, 6), n = e.type, l = e.image, s = null;
        if (1 == n) {
            s = _[this.fTypeCount - 1];
            3 == this.fTypeCount && (s = s.replace(/money/g, i.toString()));
            this.fTypeCount += 1;
            this.fTypeCount > 3 && (this.fTypeCount = 1);
        } else {
            i || (i = e.money);
            s = (s = _[n + 1]).replace(/money/g, i.toString());
        }
        s = s.replace(/name/g, r);
        p.loadRemoteImg(l).then( (e) => {
            a.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(e);
            a.setContentSize(40, 36);
        }).catch( (e) => {
            u.log(e);
        });
        o.getComponent(cc.RichText).string = s;
        t.getComponent(cc.Layout).updateLayout();
    };
    public adjustScale(e) {
        var t = cc.winSize, a = 1;
        e.width > t.width - 240 && (a = (t.width - 240) / e.width);
        e.scale = a;
    };
    public runNoticeAction(e?, t?) {
        return;
        var a = this;
        void 0 === e && (e = null);
        void 0 === t && (t = null);
        var o = e, i = t;
        if (!o && !i) {
            o = this.ui.firstNode;
            i = this.ui.secondNode;
            o.y = 0;
            i.y = -this.ui.maskNode.height;
            this.dealShowDes(true, null);
            this.scheduleOnce(function () {
                a.adjustScale(o);
                a.adjustScale(i);
            }, 0);
            this.runCount = 2;
        }
        var r = this.ui.maskNode.height;
        this.topY = r;
        cc.tween(o).delay(3).to(1, {
            x: 0,
            y: r
        }).call(function () {
            a.runCount += 1;
            if (a.runCount > a.sroll_msg_list.length) {
                a.runCount = 1;
                a.fNode = o;
                a.sNode = i;
                h.getScollMsg();
            } else a.nextNotice(o, i, r);
        }).start();
        cc.tween(i).delay(3).to(1, {
            x: 0,
            y: 0
        }).call(function () { }).start();
    };
    public nextNotice(e, t, a) {
        e.y = -a;
        this.dealShowDes(false, e);
        this.adjustScale(e);
        var o = e;
        e = t;
        t = o;
        this.fNode = e;
        this.sNode = t;
        this.runNoticeAction(e, t);
    };
    public updateScollMsg() {
        this.sroll_msg_list = l.getSrollMsgList();
        u.log("更新公告数据======", this.sroll_msg_list);
        this.nextNotice(this.fNode, this.sNode, this.topY);
    };
    // t.prefabUrl = "assets/resources/prefabs/RollingNotice";
    // t.className = "RollingNoticeCtrl";
    // return r([y, m("UI/prefabs/RollingNoticeCtrl")], t);
}
